#if UNITY_EDITOR
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;

[CustomEditor(typeof(Game))]
public partial class GameInspector : Editor
{
    private int stage = 1;
    public override void OnInspectorGUI()
    {
        base.OnInspectorGUI();
        
        Game _this = target as Game;

        if (_this.user != null)
        {
            EditorGUILayout.LongField($"id", _this.user.id);
            EditorGUILayout.TextField($"name: {_this.user.name}");
            EditorGUILayout.IntField($"diamond" ,_this.user.diamond);
        }
      
        stage  =  EditorGUILayout.IntField($"关卡" ,stage);

        if (GUILayout.Button($"设置为关卡：{stage}"))
        { 
            Game.Instance.user.UpdateLevel(stage);
            Game.Instance.LoadGame(stage);
        }

        if (GUILayout.Button($"Add Coin 1000"))
        {
            MGame.instance.MUser.AddCoin(1000);
        }
        if (GUILayout.Button($"截屏"))
        {
            ScreenshotHelper.Capture();
        }
        if (GUILayout.Button($"获取所有Scene代码"))
        {
            string text = "";
            GetAllScripts(Path.Combine(Application.dataPath, "0A2_Scripts/GameScene/Battle"), ref text);

            File.WriteAllText(Path.Combine(Application.dataPath, "Scripts.txt"), text);
        }
    }
    static string GetAllScripts(string dir, ref string scripts)
    {
        //string dir = Path.Combine(Application.dataPath, "0A2_Scripts/Scene");

        DirectoryInfo scriptDir = new DirectoryInfo(dir);

        foreach (var e in scriptDir.GetDirectories())
        {
            GetAllScripts(e.FullName, ref scripts);
        }

        foreach (var e in scriptDir.GetFiles())
        {
            if (Path.GetExtension(e.Name).Equals(".cs") || Path.GetExtension(e.Name).Equals(".json"))
            {
                //GameDebug.Log($"add scripts:{e.Name}");
                //string[] lines = File.ReadAllLines(e.FullName);
                scripts += File.ReadAllText(e.FullName);
            }
        }
        return scripts;
    }
}

#endif